﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace Deployment.BuildManager.ExternalProcess.CreateSetupFile
{
    /// <summary>
    /// Interaction logic for SetupDetails.xaml
    /// </summary>
    public partial class SetupDetails : Window
    {
        private ObservableCollection<string> Items;

        public SetupDetails()
        {
            InitializeComponent();

            Items = new ObservableCollection<string>();
            
            lstInformation.ItemsSource = Items;

            Process.Instance.OutputDataReceived += new Action<string>(Process_OutputDataReceived);
        }

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;

            base.OnClosing(e);
        }

        private void Process_OutputDataReceived(string data)
        {
            if (System.Threading.Thread.CurrentThread == this.Dispatcher.Thread)
            {
                if (!string.IsNullOrEmpty(data))
                {
                    Items.Add(data);

                    lstInformation.ScrollIntoView(data);
                }                
            }
            else
            {
                this.Dispatcher.Invoke(new Action<string>(Process_OutputDataReceived), data);
            }
        }
    }
}
